var app = new Vue({
    el: '#app',
    data: {
        host: host,
        username: '',
        sku:[] ,
        orders:[],
        create_time:'',
        // mobile: '',
        // email: '',

        // nick_name: '',
        // nick_error: '',
        // histories: '',
        // email_active: false,
        // set_email: false,

        // email_error: false,
        // send_email_btn_disabled: false,
        // send_email_tip: '',
    },
    mounted: function () {
        // 获取个人信息
        // this.get_person();

        // 获取cookie中的用户名

        let u_json = $cookies.get('username')   //使用第三方库获取cookie
        let u_str = JSON.parse(u_json)    //将数据进行json反序列化
        this.username = eval(u_str)     //将unicode编码转为中文


        // this.get_person_info()

        this.get_history()


    },
    methods: {
        get_history: function () {
            // 获取用户所有订单
            axios.get(this.host + '/orders/', {
                responseType: 'json',
                withCredentials: true,
            })
                .then(response => {
                    //判断用户是否符合要求
                    if (response.data.code == 400) {
                        //next=是如果未登录要跳转的页面
                        location.href = 'admin_login.html?next='+location.href;
                        return
                    }
                    // console.log(response.data);
                    this.orders = response.data.oder_list;
                    // console.log(this.orders);
                    // this.sku = response.data.sku
                    // console.log(this.sku);
                    for (var i = 0; i < this.orders.length; i++) {
                        console.log(this.orders[i].sku);
                        this.sku.push(this.orders[i].sku)
                        // console.log(histories[i].sku);
                    }

                    // console.log(this.sku,'ss');
                    
                })
                .catch(error => {
                    console.log(error)
                });
        },
        // get_person: function () {
        //     var url = this.host + '/userinfo/'
        //     // console.log(url)
        //     axios.get(url, {
        //         responseType: 'json',
        //         withCredentials: true,
        //     })
        //         .then(response => {
        //             // console.log(response.data)
        //             if (response.data.code == 400) {
        //                 //next=是如果未登录要跳转的页面
        //                 location.href = 'login.html?next=' + location.href;
        //                 return
        //             }
        //             this.username = response.data.context.username;
        //             this.nick_name = response.data.context.nick_name;
        //             this.mobile = response.data.context.mobile;
        //             this.email = response.data.context.email;
        //             this.email_active = response.data.context.email_active;


        //         })

        //         .catch(error => {
        //             this.set_email = false;
        //             location.href = 'login.html'
        //             console.log(error.response)
        //         })
        // },
        logoutfunc: function () {
            var url = this.host + '/logout/'
            axios.delete(url, {
                responseType: 'json',
                withCredentials: true,
            })
                .then(response => {
                    // console.log(response.data)
                    location.href = 'login.html'
                })
                .catch(error => {
                    console.log(error.response)
                })
        }

    }

})